//
//  main.cpp
//  415 字符串相加
//
//  Created by Yan Zihao on 2024/9/27.
//

#include <iostream>
#include<string>
using namespace std;


class Solution
{
public:
    string addStrings(string num1, string num2)
    {
        if(num1.size() < num2.size())
            swap(num1,num2);
        int i = num1.size() - 1;
        int j = num2.size() - 1;
        int carry = 0;
        string s;
        while(i >= 0 || j >= 0)
        {
            int x = i >= 0 ? num1[i] - '0' : 0;
            int y = j >= 0 ? num2[j] - '0' : 0;
            int result = ((x + y +carry) % 10) + '0';
            carry = (x + y) / 10;
            s.push_back(result);
            i--;
            j--;
        }
        reverse(s.begin(),s.end());
        return s;
        
    }
};

int main(void)
{
    string s = Solution().addStrings("123", "30");
    cout << s <<endl;
    return 0;
}
